<?php

use Illuminate\Support\Facades\Storage;
use App\Models\User;

function storage_url($path) {
    return Storage::url($path);
}

function get_user_loc(User $u){
    $meta = unserialize($u->meta);
    return $meta['luo_pro'] . $meta['luo_city'];
}

function get_user_job(User $u){
    $meta = unserialize($u->meta);
    return $meta['job'];
}

function get_text_desc($text, $length=50){
    return mb_substr(strip_tags($text), 0, $length);
}

function get_wechat_auth_url($url, $scope='snsapi_base'){
    $appid = config('wechat.app_id');
    $url = urlencode($url);
    return "https://open.weixin.qq.com/connect/oauth2/authorize?" .
           "appid=$appid&redirect_uri=$url&response_type=code&" .
           "scope=$scope&state=STATE#wechat_redirect";
}
